package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.dto.PutStatusDTO;
import com.itheima.service.OrderService;
import com.itheima.vo.OrderPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author msi
 */
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService service;

    @PutMapping("")
    public R<String> updateStatus(@RequestBody PutStatusDTO putStatusDTO) {
        Boolean flag = service.updateStatus(putStatusDTO);
        if (flag){
            return R.success("操作成功");
        }
        return R.error("操作失败");
    }

    @GetMapping("/page")
    public R<OrderPageVO> getPageList
            (@RequestParam(value = "beginTime", required = false) String beginTime,
             @RequestParam(value = "endTime", required = false) String endTime,
             @RequestParam(value = "number", required = false) String number,
             @RequestParam("page") Integer page,
             @RequestParam("pageSize") Integer pageSize
            ) {
        OrderPageVO pageList = service.getPageList(beginTime, endTime, number, page, pageSize);

        return R.success(pageList);
    }
}
